﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Services
{
    public class Generica
    {

        static string uri = "";
        static string serverIp = "10.25.235.6";
        static string Username = "ftp3209";
        static string Password = "ftpvale3209";
        public static string user_banco = "user_site";
        public static string senha_banco = "user32site09";

        public static string caminho_arquivos_salvos { get; set; }

        public byte[] getMD5Hash(string input)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
            byte[] hash = md5.ComputeHash(inputBytes);
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            return hash;

            //for (int i = 0; i < hash.Length; i++)
            //{
            //    sb.Append(hash[i].ToString("X2"));
            //}
            //return "0x" + sb.ToString();
        }



        public static FtpWebRequest FTPDetail(string FileName)
        {

            uri = "ftp://" + serverIp + "/ftp_shares/FTP/arquivos_intranet/" + FileName;

            FtpWebRequest objFTP;
            objFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
            objFTP.Credentials = new NetworkCredential(Username, Password);
            objFTP.UsePassive = true;
            objFTP.KeepAlive = false;
            objFTP.Proxy = null;
            objFTP.UseBinary = false;
            objFTP.Timeout = 900000000;

            return objFTP;
        }


        public static FtpWebRequest FTPDetail_downloads(string FileName)
        {

            uri = "ftp://" + serverIp + "/ftp_shares/FTP/arquivos_downloads/" + FileName;

            FtpWebRequest objFTP;
            objFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
            objFTP.Credentials = new NetworkCredential(Username, Password);
            objFTP.UsePassive = true;
            objFTP.KeepAlive = false;
            objFTP.Proxy = null;
            objFTP.UseBinary = false;
            objFTP.Timeout = 900000;

            return objFTP;
        }


        public static FtpWebRequest FTPDetail_mobile(string FileName)
        {

            uri = "ftp://" + serverIp + "/ftp_shares/FTP/atualizacões/mobile/" + FileName; 
             FtpWebRequest objFTP;
            objFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
            objFTP.Credentials = new NetworkCredential(Username, Password);
            objFTP.UsePassive = true;
            objFTP.KeepAlive = false;
            objFTP.Proxy = null;
            objFTP.UseBinary = false;
            objFTP.Timeout = 900000;

            return objFTP;
        }


        public static string removerAcentos_minuscula(string texto)
        {
            string comAcentos = "ÄÅÁÂÀÃäáâàãÉÊËÈéêëèÍÎÏÌíîïìÖÓÔÒÕöóôòõÜÚÛüúûùÇç";
            string semAcentos = "AAAAAAaaaaaEEEEeeeeIIIIiiiiOOOOOoooooUUUuuuuCc";

            for (int i = 0; i < comAcentos.Length; i++)
            {
                texto = texto.Replace(comAcentos[i].ToString(), semAcentos[i].ToString());
            }
            return texto.ToLower();
        }

        public static string retorna_data(DateTime campo)
        {
            try
            {
                return String.Format(campo.ToString(), "yyyy-MM-dd");
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }


        public static byte[] StreamToBytes(Stream input)
        {
            byte[] buffer = new byte[16 * 1024];
            using (MemoryStream ms = new MemoryStream())
            {
                int read;
                while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                return ms.ToArray();
            }
        }


    }

}
